#include "matrix.h"
using namespace std;

int main()
{
	int lines, rows;
loop:
	cout << "Please input lines and rows:" << endl;
	cin >> lines >> rows;
	// 处理不合法输入
	if (cin.fail())
	{
		cin.clear();
		cin.ignore(numeric_limits<streamsize>::max(), '\n');
		cerr << "Illegal input!" << endl;
		goto loop;
	}
	if (lines < 0 || rows < 0)
	{
		cerr << "Out of range!" << endl;
		goto loop;
	}

	Matrix A1(lines, rows), A2(lines, rows), A3(lines, rows);
	cout << "Please input A1:" << endl;
	cin >> A1;
	cout << "Please input A2:" << endl;
	cin >> A2;
	A3 = A1 + A2;
	cout << "A3 = A1 + A2 =" << endl;
	cout << A3 << endl;
	A3 = A1 - A2;
	cout << "A3 = A1 - A2 =" << endl;
	cout << A3 << endl;

	Matrix *pA1, *pA2, *pA3;
	pA1 = new Matrix(lines, rows);
	pA2 = new Matrix(lines, rows);
	pA3 = new Matrix(lines, rows);
	cout << "Please input pA1:" << endl;
	cin >> *pA1;
	cout << "Please input pA2:" << endl;
	cin >> *pA2;
	*pA3 = *pA1 + *pA2;
	cout << "pA3 = pA1 + pA2 =" << endl;
	cout << *pA3 << endl;
	*pA3 = *pA1 - *pA2;
	cout << "pA3 = pA1 - pA2 =" << endl;
	cout << *pA3 << endl;
	delete pA1;
	delete pA2;
	delete pA3;
	system("pause");
	return 0;
}
